<?php
include "Photo.class.php";
class Album {
	var $id;
	var $description;
	var $nofotos;
	var $fecha;
	var $foto; 
	var $pictures;
	var $arrAlbums;
	
	function Album($id,$desc,$nofotos,$fecha)
	{
		$this->id=$id;
		$this->description=$desc;
		$this->nofotos=$nofotos;
		$this->fecha=$fecha;
		$this ->foto= new Photo();
	}
	

	public static function getAlbums($object)
	{
		$sql="SELECT * FROM albums WHERE idalbum in (SELECT DISTINCT idalbum FROM photos) ";
		$rs=DataBase::ExecuteQuery($sql, "ARRAY");
		
		foreach ($rs as $row => $value)
		{
			$album= Album::getOneAlbum($value['idalbum']);
			
			$album->foto->getOnePhotoRandom($album->id);
			
			array_push($object, $album);
						
		}		
		return $object;
		
	}
	
	
	
	public static function getOneAlbum($idalbum)
	{
		
		$ab=null;
		$sql="SELECT a.idalbum, a.descripcion, COUNT(1) nophotos, a.fecha
		FROM albums a, photos p 
		WHERE a.idalbum=p.idalbum
		AND a.idalbum=".$idalbum."
		GROUP BY a.idalbum, a.descripcion, a.fecha";
		
		$rs=DataBase::ExecuteQuery($sql, "ARRAY");
		
		//if(count($rs)>0)
		$ab=new Album($rs[0]['idalbum'], $rs[0]['descripcion'], $rs[0]['nophotos'], $rs[0]['fecha']);
		
		return $ab;
		
	}
	
	
}

?>